import {http} from "@/utils";
import type {ResType} from "@/apis/ResType";

// 请求频道列表
// 定义具体的接口类型
export type ChannelItem = {
    id: number
    name: string
}

type ChannelRes = {
    channels: ChannelItem[]
}

// 频道列表发送请求
export function fetchChannelAPI() {
    return http.request<ResType<ChannelRes>>({
        url: '/channels'
    })
}

// ======================================

// 请求文章列表
// 定义具体的接口类型
export type ArticleItem = {
    art_id: string
    title: string
    aut_id: string
    comm_count: number
    pubdate: string
    aut_name: string
    is_top: 0 | 1
    cover: {
        type: 0 | 1 | 3
        images: string[]
    }
}

export type ArticleRes = {
    results: ArticleItem[]
    pre_timestamp: string
}

type ArticleReqParams = {
    channel_id: string
    timestamp: string
}

// 文章列表发送请求
export function fetchArticleAPI(params: ArticleReqParams) {
    return http.request<ResType<ArticleRes>>({
        url: '/articles',
        params
    })
}
